package cert.model;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.sql.Timestamp;

import sun.security.pkcs.PKCS10;

public class CSR {
	
	private int state;
	private PKCS10 pkcs10;
	private int id;
	private Timestamp date;
	
	
	public CSR(int id,Timestamp date,int state, PKCS10 pkcs10) {
		super();
		this.date = date;
		this.id = id;
		this.state = state;
		this.pkcs10 = pkcs10;
	}


	public int getState() {
		return state;
	}


	public void setState(int state) {
		this.state = state;
	}


	public PKCS10 getPkcs10() {
		return pkcs10;
	}


	public void setPkcs10(PKCS10 pkcs10) {
		this.pkcs10 = pkcs10;
	}


	public int getId() {
		return id;
	}


	public void setId(int id) {
		this.id = id;
	}


	public Timestamp getDate() {
		return date;
	}


	public void setDate(Timestamp date) {
		this.date = date;
	}
	
	public String getPKCS10String() {

		ByteArrayOutputStream bs = new ByteArrayOutputStream();
		PrintStream ps = new PrintStream(bs);

		try {
			pkcs10.print(ps);
		} catch (Exception e) {
			e.printStackTrace();
		}

		byte[] c = bs.toByteArray();
		try {
			if (ps != null)
				ps.close();
			if (bs != null)
				bs.close();
		} catch (Throwable th) {
		}
		return new String(c);
	}

}
